package pl.mmadej.ds4java.ds.common;


public class DataStructure<T> {

    protected void assertNotNull(T t) {
        if (t == null) {
            throw new NullPointerException();
        }
    }

    protected void assertIndexInBounds(int index, int lowerBoundInclusive, int upperBoundInclusive) {
        if (index > upperBoundInclusive || index < lowerBoundInclusive) {
            throw new IndexOutOfBoundsException();
        }
    }

    @SuppressWarnings("unchecked")
    protected <E> E[] createArrayIfNeeded(E[] resultArray, int noOfElements) {
        if (resultArray.length != noOfElements) {
            resultArray = (E[]) java.lang.reflect.Array.newInstance(resultArray.getClass().getComponentType(), noOfElements);
        }
        return resultArray;
    }
}
